#!/usr/bin/env python

# encoding: utf-8

'''
 * Create File linkedin_account_keep_script_spider
 * Created by leixu on 2017/12/11
 * IDE PyCharm
'''
from luobo.spider.spiders import SeleniumBaseSpider, AsyncCrawlerRuler
from luobo.spider.base_spider import ScriptRunMode
from apscheduler.schedulers.blocking import BlockingScheduler


class LinkedinSpider(SeleniumBaseSpider):
    def __init__(self):
        super(LinkedinSpider, self).__init__()
        self.RUN_MODE = ScriptRunMode.LOCAL
        self.setting.PARALLEL_WORKER_NUMBERS = 1

    def start_crawler(self):
        ruler = AsyncCrawlerRuler()
        ruler.load_script("./script/linkedin.py")
        ruler.rule_index = 1
        self.crawler_feeder.add(ruler, self.do_process)

        # ruler2 = AsyncCrawlerRuler()
        # ruler2.load_script("./script/linkedin.py")
        # ruler2.rule_index = 1
        # self.crawler_feeder.add(ruler2, self.do_process)

    def do_process(self, response):
        print("end")
        print(response)

    def add_params(self):
        args = [
            {"username": "puzzle.x.y@outlook.com", "password": "!qaz2wsx3edc"},
            {"username": "zhouxy0626@163.com", "password": "#edc2wsx1qaz"},
            {"username": "zhouxy0626@126.com", "password": "!qaz2wsx3edc"},

            {"username": "muzili.w0612@outlook.com", "password": "!qaz2wsx3edc"},
            {"username": "nancy-data2017@hotmail.com", "password": "!qaz2wsx"},

            {"username": "hanhongfei1001.x@outlook.com", "password": "!qaz2wsx3edc"},

            {"username": "huyitian.hyt@outlook.com", "password": "!qaz2wsx3edc"},
            {"username": "malama001.ml@outlook.com", "password": "!qaz2wsx3edc"},

            {"username": "huayi123.feng@outlook.com", "password": "!qaz2wsx3edc"},

            {"username": "wusanyi22.w.s@outlook.com", "password": "!qaz2wsx3edc"},
            {"username": "x.y.zhou626@outlook.com", "password": "!qaz2wsx3edc"},

            {"username": "lv.pg.one131@outlook.com", "password": "!qaz2wsx3edc"},
            {"username": "wen101.tiankong@outlook.com", "password": "!qaz2wsx3edc"},

            {"username": "zhjy.404.two@outlook.com", "password": "!qaz2wsx3edc"},
            {"username": "jing.yu.74@outlook.com", "password": "!qaz2wsx3edc"},

            "-1endflag",
            "-1endflag",
            "-1endflag"]
        self.params_deliver.add_params(*args)

    def print_state(self):
        print(self.spider_state)


def process_1():
    b = LinkedinSpider()
    b.start_crawl()


if __name__ == "__main__":
    loop_round = 1

    # The "apscheduler." prefix is hard coded

    while True:
        process_1()
        import time

        print("loop_round" + str(loop_round))
        loop_round += 1
        time.sleep(60)
